package Views;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

import entries.IngredientEntry;

import Models.Ingredient;
import javax.swing.JScrollPane;


public class IngredientFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private JPanel contentPane;
	JPanel ingredientPnl;
	
	private ArrayList<Ingredient> ingredients;  //contains ingredients for this view
	private ArrayList<IngredientEntry> ingPnls;

	/**
	 * Create the frame.
	 */
	public IngredientFrame(ArrayList<Ingredient> ingredients) {
		this.ingPnls = new ArrayList<IngredientEntry>();
		this.ingredients = ingredients;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
		setBounds(100, 100, 450, 300);
		
		JScrollPane scrollPane = new JScrollPane();

		ingredientPnl = new JPanel();
		ingredientPnl.setLayout(new BoxLayout(ingredientPnl, BoxLayout.Y_AXIS));
		scrollPane.setViewportView(ingredientPnl);
		
		initializeIngredients();
		getContentPane().add(scrollPane, BorderLayout.CENTER);
		revalidate();
	}
	
	/**
	 * initializes the view to show the initial ingredients
	 */
	private void initializeIngredients() {
		for(Ingredient ing: ingredients) {
			IngredientEntry ie = new IngredientEntry(this, ing);
			ingPnls.add(ie);
			ingredientPnl.add(ie, BorderLayout.NORTH);
		}
	}
	
	public void removeEntry(IngredientEntry old) {
		ingredientPnl.remove(old);
		revalidate();
	}

}
